package cc.autoapi.pucong.auto.flow.core.flow.execNode.ai.text;


import cc.autoapi.pucong.auto.flow.core.flow.execNode.ai.send.AbstractAiSendSendTool;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.ai.send.handler.TransAiHandlerSend;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.exception.AutoDesignException;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.selfenum.AiTypeEnum;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.selfenum.NodeTypeEnum;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.streamBus.IStreamSubscriber;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.utils.AiJsonUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author: cong.pu
 * @create: 2024-10-14 10:35
 **/
@Slf4j
public class DefaultAiText extends AbstractAiText {


    public DefaultAiText() {

    }

    public DefaultAiText(String appId, String appKey) {
        TransAiHandlerSend transAiHandlerSend = new TransAiHandlerSend(appId, appKey);
        initAiTool(transAiHandlerSend);
    }

    @Override
    public String getText(String desc, String content) {
        AbstractAiSendSendTool aiSendSendTool = getAiSendSendTool();
        if (aiSendSendTool == null) {
            throw new AutoDesignException("aiSendSendTool is null");
        }
        AiTypeEnum aiType = AiTypeEnum.生成text内容;
        String promptFromJsonFile = AiJsonUtils.getPromptFromJsonFile(aiType);
        promptFromJsonFile = promptFromJsonFile.replace("{desc}", desc);

        log.info("promptFromJsonFile:{}", promptFromJsonFile);
        log.info("question:{}", content);
        aiSendSendTool.initSystem(promptFromJsonFile);
        String s = aiSendSendTool.sendToAi(content);
        return s;
    }

    @Override
    public IStreamSubscriber getScriptStream(String desc, String content) {
        return null;
    }
}
